<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/template.xhtml">
    <ui:define name="content">
    <h:form id="form" align="center">
    <div id="iddiv" align="center" style="width : 800px;font-size: 10pt" >
    <br />
    <p:panel id="idpanel" rendered="#{patientBean.action == 'delete' || patientBean.action == 'find' || patientBean.action == 'update'}">
    	<h:message for="patientId"/>
    	<f:facet name="header">
    		<h:outputText value="Find Patient By ID" />
		</f:facet>
    	<h:panelGrid columns="3">
    				<h:outputText value="Patient Id: " />
        			<p:inputText value="#{patientBean.patientId}" id="patientId" required="true" />
        			<h:commandButton action="#{patientBean.findPatientById}" value="Search" update="patients"/>
    	</h:panelGrid>
    </p:panel>
    </div>
    </h:form>
    <h:form>
		<div id="block" align="center" style="width : 800px; font-size: 10pt" >
		<p:panel id="panel">
		<h:messages/>
    	<f:facet name="header">
    		<h:outputText value="Find Prescription by Patient" />
		</f:facet>
    	<h:panelGrid columns="7">
    				<h:outputText value="First Name: " />
        			<p:inputText value="#{patientBean.firstName}" id="firstname" required="true" />
        			<h:outputText value="Last Name: " />
        			<p:inputText value="#{patientBean.lastName}" id="lastname" required="true" />
        			<h:outputText value="Date of Birth: " />
        			<p:calendar value="#{patientBean.dateOfBirth}" id="dob" maxdate="#{patientBean.maxDate}"/>  
        			<h:commandButton action="#{patientBean.searchPatient}" value="Search" update="patients" />
    	</h:panelGrid>
    	</p:panel>
    	<br />
    	</div>
    </h:form>
    <h:form>
    <div id="block1" align="center" style="width : 800px; font-size: 10pt" >	
    <p:panel>
        	<p:dataTable id="patients" var="curpatient" value="#{patientBean.patientList}" paginator="true" rows="10">  
  
        		<p:column headerText="Patient Id" style="width:5%">  
            		<h:outputText value="#{curpatient.patientId}" />  
        		</p:column>  
  
        		<p:column headerText="First Name" style="width:20%">  
            		<h:outputText value="#{curpatient.firstName}" />  
    	    	</p:column>  
  	
        		<p:column headerText="Last Name" style="width:20%">  
            		<h:outputText value="#{curpatient.lastName}" />  
        		</p:column>  
  
        		<p:column headerText="Middle Initial" style="width:5%">  
            		<h:outputText value="#{curpatient.middleInitial}" />  
        		</p:column>  
  
  				<p:column headerText="Age" style="width:5%">  
            		<h:outputText value="#{curpatient.age}" />  
        		</p:column> 
        		
        		<p:column headerText="Date of Birth" style="width:20%">  
            		<h:outputText value="#{curpatient.dob}" />  
        		</p:column> 
        		
        		<p:column style="width:20%; text-align : center">  
                	<h:commandButton id="createButton" action="#{patientBean.createPrescription}" value="Create" rendered="#{patientBean.action == 'prescription'}">  
                	<f:setPropertyActionListener value="#{curpatient}" target="#{patientBean.patient}" /> 
    				<f:param name="patientId" value="#{curpatient.patientId}" />
    				<f:param name="action" value="#{patientBean.action}" />
            		</h:commandButton>   
                	<h:commandButton id="updateButton" action="#{patientBean.update}" value="Update" rendered="#{patientBean.action == 'update'}">  
                	<f:setPropertyActionListener value="#{curpatient}" target="#{patientBean.patient}" /> 
    				<f:param name="patientId" value="#{curpatient.patientId}" />
    				<f:param name="action" value="#{patientBean.action}" />
            		</h:commandButton>   
                	<h:commandButton id="deleteButton" action="#{patientBean.delete}" value="Delete" rendered="#{patientBean.action == 'delete'}">  
                	<f:setPropertyActionListener value="#{curpatient}" target="#{patientBean.patient}" /> 
    				<f:param name="patientId" value="#{curpatient.patientId}" />
    				<f:param name="action" value="#{patientBean.action}" />
            		</h:commandButton> 
            		<h:commandButton id="viewButton" action="#{patientBean.view}" value="View" rendered="#{patientBean.action == 'find'}">  
                	<f:setPropertyActionListener value="#{curpatient}" target="#{patientBean.patient}" /> 
    				<f:param name="patientId" value="#{curpatient.patientId}" />
    				<f:param name="action" value="#{patientBean.action}" />
            		</h:commandButton> 
       	 		</p:column>  
  
    	</p:dataTable>  
        	
    		</p:panel>
		</div>

		</h:form>

    </ui:define>
</ui:composition>
